use std::collections::BTreeMap;

use anyhow::Result;
use reqwest::Client;

use crate::credential::MchCredential;

#[derive(Debug, Clone)]
pub struct TongLianPayClient {
    pub base_url: String,
    pub client: Client,
    pub mch_credential: MchCredential,
}
impl TongLianPayClient {
    pub fn new(mch_credential: MchCredential, base_url: String) -> Result<TongLianPayClient> {
        let client = Client::builder().build()?;
        Ok(TongLianPayClient {
            base_url,
            client,
            mch_credential,
        })
    }
    pub fn default(mch_credential: MchCredential) -> Result<TongLianPayClient> {
        TongLianPayClient::new(mch_credential, "https://vsp.allinpay.com".to_string())
    }
    pub fn verify_signature(&self, response: &mut BTreeMap<String, String>) -> Result<()> {
        self.mch_credential.verify_response(response)
    }
}
